package com.object;

import com.Inter.Verify_;
import com.ksyun.ks3.exception.serviceside.NotFoundException;
import com.ksyun.ks3.service.Ks3;
import com.ksyun.ks3.service.Ks3Client;
import com.ksyun.ks3.service.Ks3ClientConfig;
import com.ksyun.ks3.service.request.HeadObjectRequest;

import java.util.List;

public class Verify implements Verify_{
    @Override
    public void verify(String filename,String url) {
        String endpoint = "ks3-cn-beijing.ksyuncs.com";
        String accessKeyId = "AKLT47cMow9ATUKikK12_8WVXg";
        String accessKeySecret = "OJ+Jx5STAbkA7nXTU+bsfdL2w2SekBsbYv4ASsmUCvHiuKnnMyTDWIOIAj4yXoissg==";
        Ks3ClientConfig config = new Ks3ClientConfig();
        config.setEndpoint(endpoint);
        Ks3 client = new Ks3Client(accessKeyId, accessKeySecret, config);
        try {
            HeadObjectRequest request = new HeadObjectRequest("fstv-cdn",url);
            client.headObject(request);
        } catch (NotFoundException e) {
            System.out.println("存在无效URL:"+"文件名："+filename+"  "+"无效url："+url);
            System.exit(1);
        }
    }

    public void Verify_Exchange(String path){
        // 1.读取文件，得到Objets和StreamID
        Get_File gf = new Get_File();
        gf.Get_File(path);
        List<String> objects = gf.objects;
        // 文件名
        String streamID = gf.StreamID;

        Verify vfy = new Verify();
        for(String value:objects){
            value=value.replaceAll("fstv-cdn.ks3-cn-beijing.ksyuncs.com/","");
            vfy.verify(streamID,value);
        }
    }
}
